/***************************************************************************
 * This program is free software; you can redistribute it and/or           *
 * modify it under the terms of the GNU General Public License             *
 * as published by the Free Software Foundation; either version 2          *
 * of the License, or (at your option) any later version.                  *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License       *
 * along with this program; if not, write to the Free Software Foundation, *
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.         *
 *                                                                         *
 *   Copyright (C) 2007,2008 by Ivan Vucica                                *
 *   ivucica@gmail.com                                                     *
 ***************************************************************************/

#ifndef __TURTLE_H
#define __TURTLE_H

#include <math.h>
struct Color {
	Color operator= (char i) {
		h = i >> 3 & 1;
		r = i >> 2 & 1;
		g = i >> 1 & 1;
		b = i >> 0 & 1;
		return *this;
	}
	/*char operator= (Color i) {
		return h * 8 + r * 4 + g * 2 + b * 1;
	}*/
	Color operator= (Color i) {
		h = i.h; r = i.r; g = i.g; b = i.b;
		return *this;
	}
	bool operator== ( char a) {
		return 	(h == a >> 3 & 1) &&
				(r == a >> 2 & 1) &&
				(g == a >> 1 & 1) &&
				(b == a >> 0 & 1);
	}
	unsigned char h:1, r:1, g:1, b:1;

} ;
class Turtle {
	public:
		Turtle () {
			posx = 0; posy = 50; rot = 270; col = 15; visibility = true; pendown = true;
		}
		void Move(double amount) {
			posx += cos(rot * 3.1415917 / 180.) * amount;
			posy += -sin(rot * 3.1415917 / 180.) * amount;
		}
		void Rotate(double amount) {
			rot += amount;
		}
		void SetColor(Color ncol) {
			col = ncol;
		}
		double GetX() {return posx;}
		double GetY() {return posy;}
		double GetRot() {return rot;}
		Color GetColor() {return col;}
		bool IsVisible() {return visibility;}
		void Hide() {visibility = false; }
		void Show() {visibility = true; }
		bool IsPenDown() {return pendown;}
		void PenUp() {pendown = false;}
		void PenDown() {pendown = true;}
	private:
		double posx, posy;
		double rot;
		Color col;
		bool visibility;
		bool pendown;
};

#endif
